package cn.ac.registAService.commons.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

/**
 * 
 * @author dizi
 * @date 2011-05-19
 * 
 */
public class DateTimeTool {

	public static SimpleDateFormat parser = new SimpleDateFormat(
			"yyyy-MM-dd'T'HH:mm:ss");

	/**
	 * 文本转换为日期
	 * @param xmlDateTime
	 *           2011-05-31T11:00:00
	 * @return java Date
	 */
	public static Date getJavaDate(String xmlDateTime) {

		Date date = null;

		try {
			date = parser.parse(xmlDateTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return date;
	}

	/**
	 * 日期转换为文本
	 * @param javaDate
	 * 
	 * @return 2011-05-31T11:00:00
	 */
	public static String getXMLDateTime(Date javaDate) {

		return parser.format(javaDate);
	}

	/**
	 * Test main
	 * @param args
	 */
	public static void main(String[] args) {

		Date date1 = getJavaDate("2011-05-31T11:00:00");
		String date2 = getXMLDateTime(new Date());
		
		System.out.println(date1);
		System.out.println(date2);

	}
}
